﻿using Newtonsoft.Json;
using Sustainalytics.FileManager;
using Sustainalytics.LongRunningTaskManager.Interface;
using System.Collections.Generic;

namespace Sustainalytics.LongRunningTaskManager
{
    /// <summary>
    /// Task result used in conjunction with file manager.
    /// </summary>
    public class LongRunningTaskFileManagerResult : ILongRunningTaskResult, IEqualityComparer<LongRunningTaskFileManagerResult>
    {
        /// <summary>
        /// Result type.
        /// </summary>
        public LongRunningTaskResultTypeEnum Type
        {
            get { return LongRunningTaskResultTypeEnum.FileManager; }
        }

        /// <summary>
        /// File path.
        /// </summary>
        public string FilePath { get; set; }

        /// <summary>
        /// File manager.
        /// </summary>
        [JsonIgnore]
        private IFileManager FileManager { get; set; }


        /// <summary>
        /// Ctor.
        /// </summary>
        public LongRunningTaskFileManagerResult()
        {
        }

        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="filePath"> File path. </param>
        /// <param name="fileManager"> File manager. </param>
        public LongRunningTaskFileManagerResult(string filePath, IFileManager fileManager)
        {
            this.FilePath = filePath;
            this.FileManager = fileManager;
        }


        public bool Equals(ILongRunningTaskResult x, ILongRunningTaskResult y)
        {
            if (x == null && y == null)
                return true;

            if (x == null || y == null)
                return false;

            if (x is LongRunningTaskFileManagerResult && y is LongRunningTaskFileManagerResult)
            {
                var eq = new LongRunningTaskFileManagerResult().Equals((LongRunningTaskFileManagerResult)x, (LongRunningTaskFileManagerResult)y);
                return eq;
            }
            else
            {
                return false;
            }
        }

        public int GetHashCode(ILongRunningTaskResult obj)
        {
            return 0;
        }

        public bool Equals(LongRunningTaskFileManagerResult x, LongRunningTaskFileManagerResult y)
        {
            if (x == null && y == null)
                return true;

            if (x == null || y == null)
                return false;

            return x.FilePath == y.FilePath;
        }

        public int GetHashCode(LongRunningTaskFileManagerResult obj)
        {
            return obj == null || obj.FilePath == null ? 0 : this.FilePath.GetHashCode();
        }
    }
}
